package mvp.com.bbc.newrelyframes.app.uitls;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ${cbf} on 2017/12/5.
 * 活动界面的管理类
 */

public class ActivityUtils {
    private static List<Activity> list = new ArrayList<>();

    /**
     * 添加活动
     */
    public static void add(Activity activity) {
        list.add(activity);
    }

    /**
     * 移除活动
     */
    public static void removeActivity(Activity activity) {
        list.remove(activity);
    }

    /**
     * 返回上一个界面
     */
    public static void break_off() {
        list.get(list.size() - 1).finish();
    }

    /**
     * 移除全部活动
     */
    public static void removeAllActivity() {
        for (Activity activity : list) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
    }

    /**
     * 关闭所有活动除了自己
     */
    public static void removeAllExceptActivity(Activity a) {
        for (Activity activity : list) {
            if (!activity.isFinishing() && a != activity) {
                activity.finish();
            }
        }
    }

    /**
     * 添加参数并进行进入下一个界面
     */
    public static void skipAddActivity(Class<?> clazz, Bundle bundle) {
        Intent intent=new Intent(list.get(0),clazz);
        list.get(0).startActivity(intent,bundle);
    }
}
